<?php


namespace app\common\model;


use think\Model;

class AdminRole extends Model {

    /**
     * 取角色的操作权限数组
     * @param $id
     * @return array|\think\Config
     */
    public function getRoleOperation($role_id,$manage_id)
    {
        $result = [
            'status' => true,
            'data'   => [],
            'msg'    => ''
        ];

        $where['id']    = $role_id;
        $info = $this->where($where)->find();
        if (!$info) {
            return error_code(11071);
        }
        $mrorModel = new AdminRoleOperationRel();
        $permList  = $mrorModel->where(['admin_role_id' => $role_id])->select();
        if (!$permList->isEmpty()) {
            $nodeList = array_column($permList->toArray(), 'operation_id');
        } else {
            $nodeList = [];
        }


        $operationModel = new Operation();
        $manageMenu = $operationModel->manageMenu($manage_id,$operationModel::PERM_TYPE_HALFSUB);           //当前登陆者的后台菜单树
        $result['data'] = $operationModel->setRoleManageMenu($manageMenu,$nodeList);

        return $result;
    }


}